﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MINERP.MODEL.FoundationModel;
using MINERP.DAL;

namespace MINERP.BLL.Statistics
{
    public class ShopBillIndexBLL
    {
        private DAL.Statistics.ShopBillIndexDAL dal = new MINERP.DAL.Statistics.ShopBillIndexDAL();

        #region 所有商户
        /// <summary>
        /// 所有商户
        /// </summary>
        /// <returns></returns>
        public List<ShopCL> GetShops()
        {
            try
            {
                DataTable dt = dal.GetShops();
                List<ShopCL> shops = new List<ShopCL>();
                foreach (DataRow r in dt.Rows)
                {
                    ShopCL s = new ShopCL();
                    s.ShopId = Convert.ToInt32(r["ShopId"]);
                    s.ShopName = r["ShopName"].ToString();
                    shops.Add(s);
                }
                shops = shops.OrderBy(p => p.ShopName).ToList();
                return shops;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 时间段内的账单及商户信息
        /// <summary>
        /// 时间段内的账单及商户信息
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="shopId"></param>
        /// <returns></returns>
        public DataSet GetBillByTimeSpan(DateTime start, DateTime end, int shopId,int status)
        {
            try
            {
                return dal.GetBillsByTimeSpan(start, end, shopId, status);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataSet GetBillStatistics(DateTime start, DateTime end, int status,int timeType)
        {
            try
            {
                return dal.GetBillStatistics(start, end, status,timeType);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable GetBillEditRecords(DateTime start, DateTime end)
        {
            try
            {
                return dal.GetBillEditRecord(start, end);
            }
            catch(Exception ex)
            {
                throw ex;
            }
        }

        public DataSet GetBillProduct(DateTime start, DateTime end,int shopId)
        {
            try
            {
                return dal.GetBillProduct(start, end,shopId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public List<Shop_Info> GetShopInfoByHelpCode(string inHelpCode)
        {
            List<Shop_Info> shopInfoList = new List<Shop_Info>();
            using (newSampleYPDBEntities db = new newSampleYPDBEntities())
            {
                List<Shop> listShop = db.Shop.Where(p => p.mnemonicCode.Contains(inHelpCode) && p.Status == 1).ToList();
                listShop.ForEach(s => shopInfoList.Add(new Shop_Info()
                {
                    Address = s.address,
                    Area = s.Area,
                    ShopKeeper = s.shopKeeper,
                    CreditLevel = s.CreditLevel ?? 0,
                    EmailAddr = s.EmailAddr,
                    MnemonicCode = s.mnemonicCode,
                    IsNeedPrintUPrice = s.IsNeedPrintUPrice ?? false,
                    MSN = s.MSN,
                    Tel1 = s.Tel1,
                    Tel2 = s.Tel2,
                    //PaperFaceID = s.PaperFaceId ?? 0,
                    //PaperTypeID = s.PaperTypeId ?? 0,

                    Salesman = s.Salesman,
                    Priority = s.Priority ?? 0,
                    QQ = s.QQ,
                    Remark = s.Remark,
                    ShopId = s.ShopId,
                    ShopName = s.shopName,
                    Status = s.Status ?? 0,


                }));

            }
            return shopInfoList;
        }

        #endregion

        //-----------------数据结构-----------------
        public class ShopCL
        {
            public int ShopId { get; set; }
            public string ShopName { get; set; }
        }


    }
}
